<?php

class wwy_resource_container extends foreground_action_service_container
{
    protected static $_config;
    public static function init()
    {
        require_once PROJECT_ROOT_PATH . '/no_public/common/config/config.php';
        
        self::$_config = wwy_get_all_config();
        //var_dump(self::$_config); exit();
    }

//     public static function get_config()
//     {
//         return self::$_config;
//     }
    
    public static function get_config_item($item_key)
    {
        return self::$_config[$item_key];
    }

    public static function get_business_config()
    {
        return self::$_config['business_config'];
    }


    protected static $_db;
    public static function get_db()
    {
        if(self::$_db === null){
            require_once PROJECT_ROOT_PATH . '/no_public/common/library/class/db.php';

            $options = self::$_config['db'];
            self::$_db = new wwy_db($options);
        }

        return self::$_db;
    }
    
    protected static $_write_db;
    public static function get_write_db()
    {
        if(self::$_write_db === null){
            self::$_write_db = self::get_db();
        }
    
        return self::$_write_db;
    }
    
    protected static $_page_handler;
    public static function get_page_handler()
    {
        if(self::$_page_handler === null){
            require_once PROJECT_ROOT_PATH . '/no_public/common/library/class/page_handler.php';
    
            self::$_page_handler = wwy_page_handler::get_instance();
        }
    
        return self::$_page_handler;
    }
    
    protected static $_file_handler;
    public static function get_file_handler()
    {
        if(self::$_file_handler === null){
            require_once PROJECT_ROOT_PATH . '/no_public/common/library/class/file_handler.php';
    
            self::$_file_handler = wwy_file_handler::get_instance();
        }
    
        return self::$_file_handler;
    }
    
    protected static $_image_handler;
    public static function get_image_handler()
    {
        if(self::$_image_handler === null){
            require_once PROJECT_ROOT_PATH . '/no_public/common/library/class/image_handler.php';
    
            self::$_image_handler = wwy_image_handler::get_instance();
        }
    
        return self::$_image_handler;
    }
    
    protected static $_captcha_handler;
    public static function get_captcha_handler()
    {
        if(self::$_captcha_handler === null){
            require_once PROJECT_ROOT_PATH . '/no_public/common/library/class/captcha_handler.php';
    
            self::$_captcha_handler = wwy_captcha_handler::get_instance();
        }
    
        return self::$_captcha_handler;
    }
    
    //通用缓存处理器
    protected static $_cache_handler;
    public static function get_cache_handler()
    {
        if(self::$_cache_handler === null){
            require_once PROJECT_ROOT_PATH . '/no_public/common/library/class/cache_handler.php';
    
            $options = isset(self::$_config['cache_handler']) ? self::$_config['cache_handler'] : array();
            self::$_cache_handler = new wwy_cache_handler($options);
        }
        //var_dump(self::$_cache_handler); exit();
    
        return self::$_cache_handler;
    }
    
//     //可添加其他缓存处理器，如分类数据缓存
//     protected static $_category_cache_handler;
//     public static function get_category_cache_handler()
//     {
//         if(self::$_category_cache_handler === null){
//             require_once PROJECT_ROOT_PATH . '/no_public/common/library/class/category_cache_handler.php';
    
//             $options = self::$_config['category_cache_handler'] ? self::$_config['category_cache_handler'] : array();
//             self::$_category_cache_handler = new wwy_cache_handler($options);
//         }
    
//         return self::$_category_cache_handler;
//     }
}
